home *** CD-ROM | disk | FTP | other *** search
/ Internet 53 / INTERNET53.iso / pc / software / windows / building / coldfusion studio evaluation / data1.cab / CFS_Wizards / CFML / Library_OpenFile.wml < prev    next >
Encoding:
Text File  |  1998-10-08  |  1.5 KB  |  45 lines

  1. <!--- security check --->
  2. <CFIF Find( '..', URL.ServerFile )
  3.     or Find( '\', URL.ServerFile )
  4.     >
  5.     Error: You are not allowed to access this file
  6.     <CFABORT>
  7. </CFIF>
  8.  
  9. <WIZSET LibraryDirectory = Trim(LibraryDirectory)>
  10. <WIZIF Right( LibraryDirectory, 1 ) EQ '\'>
  11.     <WIZSET LibraryDirectory = Left( LibraryDirectory, Len(LibraryDirectory) - 1 )>
  12. </WIZIF>
  13.  
  14. <!--- parameters --->
  15. <CFSET LibraryDirectory = "$${LibraryDirectory}">
  16. <CFSET FilePath = "#LibraryDirectory#\#URL.ServerFile#">
  17.  
  18.  
  19. <!--- extract the file extension --->
  20. <CFSET SeparatorPos = Find( '.', Reverse(URL.ServerFile) )>
  21. <CFIF SeparatorPos is 0> <!--- separator not found --->
  22.     <CFSET FileExt = ''>
  23. <CFELSE>
  24.     <CFSET FileExt = Right( URL.ServerFile, SeparatorPos - 1 )>
  25. </CFIF>
  26.  
  27.  
  28. <!--- find the proper MIME type --->
  29. <CFIF FileExt is ''>            <CFSET FileType = "unknown">
  30. <CFELSEIF FileExt is 'pdf'>        <CFSET FileType = "application/pdf">
  31. <CFELSEIF FileExt is 'aif'>        <CFSET FileType = "audio/aiff">
  32. <CFELSEIF FileExt is 'aiff'>    <CFSET FileType = "audio/aiff">
  33. <CFELSEIF FileExt is 'art'>        <CFSET FileType = "image/x-jg">
  34. <CFELSEIF FileExt is 'cil'>        <CFSET FileType = "application/vnd.ms-artgalry">
  35. <CFELSEIF FileExt is 'gif'>        <CFSET FileType = "image/gif">
  36. <CFELSEIF FileExt is 'htm'>        <CFSET FileType = "text/html">
  37. <CFELSEIF FileExt is 'html'>    <CFSET FileType = "text/html">
  38. <CFELSE>                        <CFSET FileType = "unknown">
  39. </CFIF>
  40.  
  41.  
  42. <!--- return requested file --->
  43. <CFCONTENT TYPE="#FileType#" 
  44.     FILE="#FilePath#"
  45. >